package com.lhy.controller;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lhy.domain.NewMessage;
import com.lhy.domain.Result;
import com.lhy.service.IUserService;



@Controller
@RequestMapping("/newmessage")
public class NewMessageController {
	@Autowired
	private IUserService userService;

	
	@RequestMapping("")
	public String toIndex(HttpServletRequest request, Model model,String newmessage_id ){
		request.setAttribute("newmessage_id", newmessage_id);
		return "newmessage";
	}
	@RequestMapping("/do")
	public @ResponseBody
	Map<String, Object> query(String newmessage_id)  {
		Map<String, Object> returnMap = new HashMap<>();
		Result result=new Result();
		result.setCode("1");
		result.setDes("成功");    
		try{
			
			NewMessage newmessage = userService.queryNewMessageById(Integer.valueOf(newmessage_id));
			returnMap.put("newmessage", newmessage);
			
		}catch(Exception e){
			e.printStackTrace();
			result.setCode("0");
			result.setDes(e.getMessage());
		}
		returnMap.put("result", result);
		return returnMap;
	}
	
	@RequestMapping("/addlike")
	public @ResponseBody
	Map<String, Object> addlike(String newmessageId)  {
		Map<String, Object> returnMap = new HashMap<>();
		Result result=new Result();
		result.setCode("1");
		result.setDes("成功");    
		try{
			
		     returnMap.put("addLikeCount", 1);
		    
		}catch(Exception e){
			e.printStackTrace();
			result.setCode("0");
			result.setDes(e.getMessage());
		}
		returnMap.put("result", result);
		return returnMap;
	}
	@RequestMapping("/addstamp")
	public @ResponseBody
	Map<String, Object> addstamp(String newmessageId)  {
		Map<String, Object> returnMap = new HashMap<>();
		Result result=new Result();
		result.setCode("1");
		result.setDes("成功");    
		try{
			
		}catch(Exception e){
			e.printStackTrace();
			result.setCode("0");
			result.setDes(e.getMessage());
		}
		returnMap.put("result", result);
		return returnMap;
	}
}
